﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace Ktra_Tin.DA
{
    class AccesData
    {
        SqlConnection con = new SqlConnection();
        public AccesData()
        {
            con.ConnectionString = "Data Source=T-PC\\SQLEXPRESS;Initial Catalog=shopcd;Persist Security Info=True;User ID=sa;Password=12345";
        }

        public void Open()
        {
            if (con.State == ConnectionState.Closed)
                con.Open();
        }

        public void Close()
        {
            if (con.State == ConnectionState.Open)
                con.Close();
        }

        public DataTable Execute_ps(string name_ps, SqlParameter[] pr)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = name_ps;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(pr);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataTable tb = new DataTable();
            adp.Fill(tb);
            return tb;
        }

    }
}
